import urllib.error
import urllib.request

# 错误记录：我竟然什么都爬取不到
try:
    urllib.request.urlopen("https://blog.csdn.net")
except urllib.error.URLError as e:
    if hasattr(e,"code"):
        print(e.code)
    if hasattr(e,"reason"):
        print(e.reason)
    print(e)